//
//  TKYFeedbackController.m
//  StationHouseHelper
//
//  Created by apple on 2018/6/15.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYFeedbackController.h"

@interface TKYFeedbackController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UILabel *stringlenghtLab;
@property (weak, nonatomic) IBOutlet UITextView *textView;

@end

@implementation TKYFeedbackController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNavUI];
    self.textView.delegate = self;
    self.descLabel.userInteractionEnabled = NO;
}

#pragma mark-- 导航
- (void)setNavUI{
    self.navigationItem.title = @"意见反馈";
    self.navigationController.navigationBar.barTintColor = KNavColor;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:19.0]}];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(sendItemAction:)];
    
    [self.textView tky_cornerWithRadius:5 borderColor:kMainColour borderWidth:1];
}

#pragma mark -- 发送按钮
- (void)sendItemAction:(UIBarButtonItem *)barButtonItem{
    NSLog(@"发送");
}

-(void)textViewDidChange:(UITextView *)textView
{
    self.descLabel.text = @"";
    self.descLabel.hidden = YES;
    //实时显示字数
    self.stringlenghtLab.text = [NSString stringWithFormat:@"%ld/100",(long)textView.text.length];
    
    //字数限制
    if (textView.text.length >= 100) {
        textView.text = [textView.text substringToIndex:100];
    }
    
    //取消按钮点击权限，并显示文字
    if (textView.text.length == 0) {
        self.descLabel.hidden = NO;
    }
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [self.textView resignFirstResponder];
        return NO;
    }
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
